﻿using JobBack.Models;
using QG.JobBack.BLL.IService;
using QG.JobBack.BLL.Service;
using QG.JobBack.Core;
using QG.JobBack.DAL;
using QH.JobBack.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JobBack.Controllers
{
    public class MenuController : BaseController
    {
        private IMenuInfoService imenuinfoservice;
        private IModuleService imoduleservice;
        public MenuController(IMenuInfoService imenuinfoservice, IModuleService imoduleservice)
        {
            this.imenuinfoservice= imenuinfoservice ;
            this.imoduleservice = imoduleservice;
        }
        Opretation opretation = new Opretation();
        /// <summary>
        /// 菜单管理页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Add()
        {
            ViewBag.parentMenu = imenuinfoservice.GetParentMenu().data; ;
            ViewBag.modulist = imoduleservice.GetModules().data;
            return View();
        }

        public JsonResult AddMenu(MenuInfo m)
        {
            ResponseResult rr = imenuinfoservice.AddMenu(m);
            return Json(rr);
        }

        public ActionResult Update(int id)
        {
            MenuInfo m = imenuinfoservice.GetMenuById(id).data;
            ViewBag.parentMenu = imenuinfoservice.GetParentMenu().data; 
            ViewBag.moduleList = imoduleservice.GetModules().data;
            return View(m);
        }

        public JsonResult UpdMenu(MenuInfo m)
        {
            ResponseResult rr = imenuinfoservice.UpdMenu(m);
            return Json(rr);
        }

        public JsonResult GetMenuList(int page, int limit, string menuName)
        {
            ResponseResult<MenuInfo> rr = imenuinfoservice.GetMenu(page, limit, menuName);
            return Json(rr, JsonRequestBehavior.AllowGet);
        }

        public JsonResult UpdateStatus(int Id, int Status)
        {
            ResponseResult rr = imenuinfoservice.UpdateStatus(Id, Status);
            return Json(rr);
        }

        public JsonResult DelMenu(string id)
        {
            ResponseResult rr = imenuinfoservice.DelMenu(Convert.ToInt32(id));
            return Json(rr);
        }


    }
}